#!/usr/bin/make -f
APP=tempgraph

application = $(CURDIR)/$(APP)
man_page = $(CURDIR)/man/$(APP).1.gz
gui = $(CURDIR)/tgui-build/tgui

DEST_APP = $(CURDIR)/debian/$(APP)/usr/bin
DEST_SHARE = $(CURDIR)/debian/$(APP)/usr/share
DEST_MAN = $(CURDIR)/debian/$(APP)/usr/share/man/man1

CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

build: build-stamp	
	g++ $(CFLAGS) $(LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) -O3 -o $(APP) src/main.cpp src/anyoption.cpp src/ghcn.cpp src/tempdata.cpp src/stationdata.cpp src/gridcell.cpp src/globalgrid.cpp src/gnuplot.cpp -Isrc
	$(MAKE) -C $(CURDIR)/tgui-build
build-stamp:
	dh_testdir
	touch build-stamp
clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	dh_clean
install: build clean $(application) $(man_page) $(gui)
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	mkdir -m 755 -p $(DEST_APP)
	mkdir -m 755 -p $(DEST_MAN)
	install -m 755 --strip $(application) $(DEST_APP)
	install -m 755 --strip $(gui) $(DEST_APP)
	install -m 644 $(man_page) $(DEST_MAN)
# desktop/menu/icon settings
	mkdir -m 755 -p $(DEST_SHARE)/applications
	mkdir -m 755 -p $(DEST_SHARE)/applications/$(APP)
	mkdir -m 755 -p $(DEST_SHARE)/pixmaps
	mkdir -m 755 -p $(DEST_SHARE)/icons
	mkdir -m 755 -p $(DEST_SHARE)/icons/hicolor
	mkdir -m 755 -p $(DEST_SHARE)/icons/hicolor/scalable
	mkdir -m 755 -p $(DEST_SHARE)/icons/hicolor/scalable/apps
	mkdir -m 755 -p $(DEST_SHARE)/icons/hicolor/24x24
	mkdir -m 755 -p $(DEST_SHARE)/icons/hicolor/24x24/apps
	install -m 644 $(CURDIR)/desktop/$(APP).desktop $(DEST_SHARE)/applications/$(APP)/$(APP).desktop
	install -m 644 $(CURDIR)/desktop/$(APP)_logo.png $(DEST_SHARE)/icons/hicolor/24x24/apps/$(APP).png
	install -m 644 $(CURDIR)/desktop/$(APP)_logo.svg $(DEST_SHARE)/icons/hicolor/scalable/apps/$(APP).svg
	install -m 644 $(CURDIR)/desktop/$(APP)_logo.svg $(DEST_SHARE)/pixmaps/$(APP).svg
binary-indep: build install
	dh_shlibdeps
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb
binary-arch: build install
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
